package com.soviet.boot.business.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.soviet.boot.business.system.entity.SysRole;
import com.soviet.boot.business.system.entity.SysUser;
import com.soviet.boot.business.system.service.ISysUserService;
import com.soviet.boot.business.system.vo.SysUserVo;
import com.soviet.boot.common.annotation.ResultAndLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author Dave
 * @since 2021/07/20
 */
@RestController
@RequestMapping("/system/user")
@ResultAndLog
public class SysUserController {
    @Autowired
    private ISysUserService sysUserService;


    @GetMapping("/page")
    public Object page(PageDTO<SysUserVo> page, SysUserVo query) {
        return sysUserService.pageList(page, query);
    }

    @GetMapping("/getUserInfo")
    public Object getUserInfo(@AuthenticationPrincipal SysUser userInfo) {
        System.out.println(userInfo);
        return userInfo;
    }

    /**
     * 新增
     *
     * @param sysRole
     * @return Object
     */
    @PostMapping("/add")
    public Object save(@RequestBody SysUser SysUser) {
        return sysUserService.addUser(SysUser);
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return Object
     */
    @GetMapping("/delete")
    public Object removeById(@RequestParam Long id) {
        return sysUserService.removeById(id);
    }

    /**
     * 修改
     *
     * @param sysRole
     * @return Object
     */
    @PostMapping("/update")
    public Object updateById(@RequestBody SysUser SysUser) {
        return sysUserService.updateById(SysUser);
    }


    @GetMapping("/accountExist")
    public Object accountExist(@RequestParam String account) {
        return sysUserService.accountExist(account);
    }
}
